package com.seedwill.common.unit.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.seedwill.common.meta.IData;
import com.seedwill.common.meta.base.AIdentity;
import com.seedwill.common.unit.ICell;

public abstract class ACell extends AIdentity implements ICell {

	public ACell(String identityName, IData identityVal,
			Serializable serializableIdentity) {
		super(identityName, identityVal, serializableIdentity);
		// TODO Auto-generated constructor stub
	}

	public ACell(String identityName, IData identityVal) {
		super(identityName, identityVal);
		// TODO Auto-generated constructor stub
	}

	public ACell(String identityName, Serializable serializableIdentity) {
		super(identityName, serializableIdentity);
		// TODO Auto-generated constructor stub
	}

	protected List<ICell> children;
	
	protected ICell parentCell;
	
	@Override
	public void addChild(ICell child) {
		if(children == null){
			children = new ArrayList<ICell>();
		}
		children.add(child);
	}

	@Override
	public List<ICell> getChildren() {
		return children;
	}

	@Override
	public ICell getParentCell() {
		return parentCell;
	}

	@Override
	public boolean hasChildren() {
		return children!=null && children.size()>0;
	}


	@Override
	public void removeChild(ICell child) {
		if(children != null){
			children.remove(child);
		}
	}

	@Override
	public void removeChildById(Serializable childId) {
		if(children != null && children.size()>0){
			for(ICell c : children){
				if(childId.equals(c.getSerializableIdentity())){
					children.remove(c);
				}
			}
		}
	}

	@Override
	public void setChildren(List<ICell> children) {
		this.children = children;
	}

	@Override
	public void setParentCell(ICell cell) {
		this.parentCell = cell;
	}

 

}
